<?php
/**
 * Created by laoyu.
 * User: hilaoyu@qq.com
 * Date: 2018/5/22
 * Time: 17:11
 */

namespace Hilaoyu\LaravelExtend\Providers;

use Hilaoyu\Utils\UtilCli;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ServiceProvider;
use Hilaoyu\LaravelExtend\Supports\Cli;

class QueueWorkServiceProvider extends ServiceProvider
{
    public function boot()
    {

        if(!Cache::get('laravelExtendQueueWorkIsRunning_'.config('app.env',''))){
            $queue_work_command = Cli::buildArtisanCommand('queue:work database --tries=3 --env='. config('app.env','') .' --queue=high,default --sleep=10');
            if(!UtilCli::hasRunning($queue_work_command)){
                UtilCli::execute($queue_work_command);
            }
            Cache::put('laravelExtendQueueWorkIsRunning'.config('app.env',''),true,Carbon::now()->addMinutes(5));
        }

    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {


    }
}
